package com.xlh.dto.courseTest.check;

import com.xlh.dto.course.CourseBasicDTO;
import com.xlh.dto.user.UserInfoDTO;
import com.xlh.pojo.course.ChapterBasic;
import com.xlh.pojo.courseTest.Practice;
import lombok.Data;

import java.util.List;
import java.util.Objects;

/**
 * @author zhr 2019/4/10
 */
@Data
public abstract class CheckDTO {
    // 答题卡id
    private Long id;
    // 试卷总分数
    private Integer score;
    // 评价(随堂练习,实验报告批阅)
    private String checkResult;

    // 课程名称
    private String courseName;
    // 章节名称
    private String chapterName;
    // 学号
    private String userNumber;
    // 姓名
    private String userName;

    // 归档文件地址
    private String pdf;
    // 归档文件名称
    private String pdfName;

    // 上一张试卷答题卡id
    private Long preview;
    // 下一张试卷答题卡id
    private Long next;

    // 评价模板id
    private Long templateId;

    public CheckDTO() {
    }

    public CheckDTO(Practice practice, List<Practice> practiceList, ChapterBasic chapter, CourseBasicDTO course, UserInfoDTO user, int score) {
        this.chapterName = chapter.getName();
        this.courseName = course.getName();
        this.userName = user.getName();
        this.userNumber = user.getUserNumber();
        this.id = practice.getId();
        this.pdf = practice.getPdf();
        this.pdfName = this.userNumber + "_" + this.userName + ".pdf";
        this.checkResult = practice.getCheckResult();
        this.score = score;
        this.templateId = practice.getTemplateId();

        for (int i = 0; i < practiceList.size(); i++) {
            Practice object = practiceList.get(i);
            if (Objects.equals(this.id, object.getId())) {
                if (i + 1 < practiceList.size()) {
                    this.next = practiceList.get(i + 1).getId();
                }
                if (i - 1 >= 0) {
                    this.preview = practiceList.get(i - 1).getId();
                }
                break;
            }
        }
    }

    public CheckDTO(int score, String checkResult) {
        this.score = score;
        this.checkResult = checkResult;
    }

    public CheckDTO(String pdf, String pdfName) {
        this.pdf = pdf;
        this.pdfName = pdfName;
    }
}
